package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Random;

public class Test1 {
    public static void main(String[] args) throws ClassNotFoundException {



        Class.forName("com.mysql.cj.jdbc.Driver");
        try(
                Connection connection= DriverManager.getConnection("jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                        "root","root");

        ){
            Statement state=connection.createStatement();
            Random r=new Random();
            for (int i = 0; i < 100; i++) {
                String name="test"+i;
                int age=r.nextInt(6)+10;
                int class_id=r.nextInt(10)+1;

                String sql="INSERT INTO student1(name ,age,class_id)" +
                    "VALUES('"+name+"',"+age+","+class_id+")";
                System.out.println(sql);
                int count=state.executeUpdate(sql);
                if(count>0){
                    System.out.println("影响了表中"+count+"条数据");
                }
            }
            System.out.println("sql执行完毕");
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
